/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package mbean.admin.customerdemand;

import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.ejb.EJB;
import model.entity.Customerdemand;
import org.omnifaces.util.Faces;
import org.primefaces.model.LazyDataModel;
import service.ICustomerdemandManager;
import service.InterfaceServiceLocal;
import utils.PageDateModel;
import utils.QueryStr;

/**
 *
 * @author dingnangen
 */
@Named(value = "customerdemandMB")
@SessionScoped
public class CustomerdemandMB implements Serializable {

    /**
     * Creates a new instance of CustomerdemandMB
     */
    public CustomerdemandMB() {
    }
    @EJB(beanName = "CustomerdemandManager")
    private ICustomerdemandManager CustomerdemandManager;

    private LazyDataModel<Customerdemand> items = null;

    private Customerdemand currentCustomerdemand;
    private Date servicedateselection = new Date();
    private final List<String> pList = new ArrayList();

    private final List<Date> datepList = new ArrayList();

    private Date copyStartDate = new Date();
    private Date copyEndDate = new Date();

    /**
     * 初始化
     */
    public void init() {
        if (Faces.isPostback()) {
            System.out.println("isPostback");
            return;
        }
        if (pList.size() == 0) {
            pList.add("servicedate");
        }
    }

    public LazyDataModel<Customerdemand> getItems() {
        datepList.clear();
        datepList.add(servicedateselection);
        System.out.println("CustomerdemandMB:LazyDataModel" + pList);
        if (items == null) {
            QueryStr qs = new QueryStr("Customerdemand", 0, pList);
            items = new PageDateModel<Customerdemand>(qs, CustomerdemandManager, datepList);

        }

        return items;
    }

    public void onSVDateChange() {
        System.out.println("CustomerdemandMB:servicedateselection:" + servicedateselection);
    }

    public void copyCD() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        CustomerdemandManager.copyCD(simpleDateFormat.format(copyStartDate), simpleDateFormat.format(copyEndDate));
    }

    public void setItems(LazyDataModel<Customerdemand> items) {
        this.items = items;
    }

    public Date getServicedateselection() {
        return servicedateselection;
    }

    public void setServicedateselection(Date servicedateselection) {
        this.servicedateselection = servicedateselection;
    }

    public Date getCopyStartDate() {
        return copyStartDate;
    }

    public void setCopyStartDate(Date copyStartDate) {
        this.copyStartDate = copyStartDate;
    }

    public Date getCopyEndDate() {
        return copyEndDate;
    }

    public void setCopyEndDate(Date copyEndDate) {
        this.copyEndDate = copyEndDate;
    }

}
